package mo.tags.stack;

import java.util.ArrayDeque;

public class L2289 {

    public int totalSteps(int[] nums) {
        int ans = 0;
        ArrayDeque<int[]> st = new ArrayDeque<>();
        for (int num : nums) {
            int maxT = 0;
            while (!st.isEmpty() && st.peek()[0] <= num)
                maxT = Math.max(maxT, st.pop()[1]);
            maxT = st.isEmpty() ? 0 : maxT + 1;
            ans = Math.max(ans, maxT);
            st.push(new int[]{num, maxT});
        }
        return ans;
    }

    public static void main(String[] args) {
        L2289 test = new L2289();
        System.out.println(test.totalSteps(new int[]{10,1,2,3,4,5,6,1,2,3}));
    }


}
